﻿<UserControl x:Class="Samba.Modules.MenuModule.MenuItemView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     mc:Ignorable="d">
    <ScrollViewer Common:KineticBehaviour.HandleKineticScrolling="True" VerticalScrollBarVisibility="Auto">
        <StackPanel>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" Margin="0,0,10,0">
                    <Label>
                        <LocText ResourceIdentifierKey="ProductName" Suffix=":"/>
                    </Label>
                    <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name,Mode=TwoWay}" />
                    <Label>
                        <LocText ResourceIdentifierKey="Barcode" Suffix=":"/>
                    </Label>
                    <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Barcode,Mode=TwoWay}" />
                    <Label>
                        <LocText ResourceIdentifierKey="Vat" Suffix=":"/>
                    </Label>
                    <ComboBox IsEditable="true" HorizontalAlignment="Left" MinWidth="150"
                     ItemsSource="{Binding VatTemplates}" SelectedValue="{Binding VatTemplate}" DisplayMemberPath="DisplayName" SelectedValuePath="Model">
                    </ComboBox>
                </StackPanel>
                <StackPanel Grid.Column="1">
                    <Label>
                        <LocText ResourceIdentifierKey="GroupCode" Suffix=":"/>
                    </Label>
                    <ComboBox HorizontalAlignment="Left" MinWidth="150" Text="{Binding GroupCode,Mode=TwoWay}"
                     ItemsSource="{Binding GroupCodes}" IsEditable="True">
                    </ComboBox>
                    <Label>
                        <LocText ResourceIdentifierKey="Tag" Suffix=":"/>
                    </Label>
                    <ComboBox HorizontalAlignment="Left" MinWidth="150" Text="{Binding Tag,Mode=TwoWay}"
                     ItemsSource="{Binding Tags}" IsEditable="True">
                    </ComboBox>
                </StackPanel>
            </Grid>

            <StackPanel Orientation="Horizontal">
                <GroupBox Header="{LocText PortionPrices}"
                         Padding="5" Margin="5">
                    <StackPanel Orientation="Horizontal">
                        <DataGrid ItemsSource="{Binding Portions}" SelectedItem="{Binding SelectedPortion, Mode=TwoWay}"
                                 HorizontalAlignment="Left" GridLinesVisibility="None" RowHeaderWidth="0" Margin="0,3"
                                 AutoGenerateColumns="False" CanUserSortColumns="False" 
                                 Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}"
                                 CellEditEnding="DataGrid_CellEditEnding">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="{LocText Portion}"
                                         MinWidth="100" Binding="{Binding Name}" />
                                <DataGridTextColumn Header="{LocText Multiplier}"
                                         Binding="{Binding Path=Multiplier,StringFormat='#,##.##'}" />
                                <DataGridTextColumn Header="{LocText Price}"
                                         Binding="{Binding Path=Price,StringFormat='#,#0.00'}" CellStyle="{StaticResource RightAlignedCellStyle}" />
                                <DataGridTextColumn Header="{LocText PB}" MinWidth="10"
                                         Binding="{Binding CurrencyCode}" />
                            </DataGrid.Columns>
                            <DataGrid.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Command="{Binding AddPortionCommand}" Header="{Binding AddPortionCommand.Caption}" />
                                    <MenuItem Command="{Binding DeletePortionCommand}" Header="{Binding DeletePortionCommand.Caption}" />
                                </ContextMenu>
                            </DataGrid.ContextMenu>
                        </DataGrid>
                        <StackPanel Margin="10">
                            <TextBlock Margin="2,3">
                                    <Hyperlink Command="{Binding AddPortionCommand}">
                                        <TextBlock Text="{Binding Path=AddPortionCommand.Caption}" />
                                    </Hyperlink>
                                </TextBlock>
                            <TextBlock Margin="2,3">
                                    <Hyperlink Command="{Binding DeletePortionCommand}">
                                        <TextBlock Text="{Binding Path=DeletePortionCommand.Caption}" />
                                    </Hyperlink>
                                </TextBlock>
                        </StackPanel>
                    </StackPanel>
                </GroupBox>
                <GroupBox Header="{LocText PropertyGroups}"
                         Padding="5" Margin="5">
                    <StackPanel Orientation="Horizontal">
                        <DataGrid ItemsSource="{Binding PropertyGroups}" SelectedItem="{Binding SelectedProperty, Mode=TwoWay}"
                                 HorizontalAlignment="Left" GridLinesVisibility="None" RowHeaderWidth="0" Margin="0,3"
                                 AutoGenerateColumns="False" CanUserSortColumns="False" Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="{LocText PropertyGroup}"
                                         MinWidth="100" Binding="{Binding Name}" />
                            </DataGrid.Columns>
                            <DataGrid.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Command="{Binding AddPropertyGroupCommand}" Header="{Binding AddPropertyGroupCommand.Caption}" />
                                    <MenuItem Command="{Binding DeletePropertyGroupCommand}" Header="{Binding DeletePropertyGroupCommand.Caption}" />
                                </ContextMenu>
                            </DataGrid.ContextMenu>
                        </DataGrid>
                        <StackPanel Margin="10">
                            <TextBlock Margin="2,3">
                                    <Hyperlink Command="{Binding AddPropertyGroupCommand}">
                                        <TextBlock Text="{Binding Path=AddPropertyGroupCommand.Caption}" />
                                    </Hyperlink>
                                </TextBlock>
                            <TextBlock Margin="2,3">
                                    <Hyperlink Command="{Binding DeletePropertyGroupCommand}">
                                        <TextBlock Text="{Binding Path=DeletePropertyGroupCommand.Caption}" />
                                    </Hyperlink>
                                </TextBlock>
                        </StackPanel>
                    </StackPanel>
                </GroupBox>
            </StackPanel>
            <Button HorizontalAlignment="Left" Margin="0,10" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                     Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </ScrollViewer>
</UserControl>